package com.example.mqtt.thread;

import com.alibaba.fastjson.JSON;
import com.example.mqtt.client.MqttClientConnect;
import com.example.mqtt.entity.properties.MQTTProperties;
import com.example.mqtt.service.FakeDataService;
import com.example.mqtt.service.RowingService;
import com.example.mqtt.tools.SlurryTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ScheduleJointsDataGroupTwo implements Runnable {
    private String rowingId;
    
    public void setRowingId(String rowingId) {
        this.rowingId = rowingId;
    }
    
    private final MQTTProperties mqttProperties;
    private final RowingService rowingService;
    private final FakeDataService fakeDataService;
    MqttClientConnect connect = MqttClientConnect.getInstance();

    public ScheduleJointsDataGroupTwo(MQTTProperties mqttProperties, RowingService rowingService, FakeDataService fakeDataService) {
        this.mqttProperties = mqttProperties;
        this.rowingService = rowingService;
        this.fakeDataService = fakeDataService;
    }

    @Override
    public void run() {
        connect.sendMessage(SlurryTools.getSplitTopic(mqttProperties.getTrain_joints_topic(), rowingService.getRowingById(rowingId).getRowingNo()), JSON.toJSONString(fakeDataService.generateRandomAngleData(rowingService.getRowingNo(rowingId), 3, 2)));
    }
}
